package com.qiall.assertutil;

import com.qiall.common.exception.BusinessException;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;

import static com.qiall.common.exception.ResultCode.*;


public class Assert {
    public static void notNull(Object obj)  {
        if(obj==null){
            throw new BusinessException(DATA_NOT_EXIST);
        }
    }
    public static void isNull(Object obj,String message)  {
        if(obj!=null){
            throw new BusinessException(DATA_ALREADY_EXIST,message);
        }
    }
    public static void isNull(Collection obj,String message)  {
        if(CollectionUtils.isNotEmpty(obj)){
            throw new BusinessException(DATA_ALREADY_EXIST,message);
        }
    }
    public static void notNull(Collection obj,String message)  {
        if(CollectionUtils.isEmpty(obj)){
            throw new BusinessException(DATA_ALREADY_EXIST,message);
        }
    }
    public static void notNull(Object obj,String message)  {
        if(obj==null){
            throw new BusinessException(DATA_NOT_EXIST,message);
        }
    }

    public static void isTrue(Boolean obj,String message)  {
        if(obj!=null&&obj.equals(true)){
         return;
        }
        throw new BusinessException(PARAM_IS_INVALID,message);
    }

}
